package com.zkthink.ceres.applet.order.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zkthink.ceres.applet.order.domain.entity.AppletProductOrder;
import com.zkthink.ceres.applet.order.domain.vo.OrderListVo;
import com.zkthink.ceres.applet.order.domain.vo.ProductOrderListVo;
import com.zkthink.clh.order.vo.MyqianbaodetailsVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.math.BigDecimal;
import java.util.List;

/**

@Author cmz
@Date 2024-04-30 9:33
*/
public interface AppletProductOrderMapper extends BaseMapper<AppletProductOrder> {
    Page<ProductOrderListVo> selectProductByPage(@Param("page") Page<ProductOrderListVo> page);

    List<MyqianbaodetailsVo> myqianbao(Long mid);

    Page<OrderListVo> selectProductOrderListByPage(@Param("page") Page<OrderListVo> page,@Param("mid") Long mid);

    @Select("select ifnull(sum(ifnull(pay_sum,0)),0) from applet_product_order aso where DATE(aso.pay_time) = CURDATE() and aso.store_id = #{storeId}")
    BigDecimal selectByToDayIncomeByStoreId(Long storeId);

    @Select("select ifnull(sum(ifnull(pay_sum,0)-ifnull(cut_amount,0)),0) from applet_product_order aso where aso.store_id = #{storeId} and pay_time is not null")
    BigDecimal selectByCumulativeIncomeByStoreId(Long storeId);

    @Select("select ifnull(sum(ifnull(pay_sum,0)),0) from applet_product_order aso where DATE(aso.pay_time) = CURDATE() and aso.vehicles_id = #{vehiclesId}")
    BigDecimal selectByToDayIncomeByVehiclesId(Long vehiclesId);

    @Select("select ifnull(sum(ifnull(pay_sum,0)),0) from applet_product_order aso where aso.vehicles_id = #{vehiclesId} and pay_time is not null")
    BigDecimal selectByCumulativeIncomeByVehiclesId(Long vehiclesId);
}